#!/bin/bash
# $0 <total reqs> <concurrent reqs> <target id>
Usage()
{
    thisfile=`basename $0`
	cat <<HELP

$thisfile -- Apache Benchmark wrapper for FPP/WPP performance testing.
USAGE: $thisfile <total reqs> <concurrent reqs> <target server id>
<target server id>:
1 - WPP Python
2 - FPP neusoft
3 - WPP Vance
4 - FPP Moto
5 - WPP Local
6 - FPP neusoft (public ip)
EXAMPLE:
#$thisfile 4000 400 2   //requst FPP neu 4000 times with 400 concurrent hits.

HELP
	exit 0
}

[ $# -eq 0 ] && Usage
ntot=$1
[ "$ntot" = "" ] && ntot=1
ncon=$2
[ "$ncon" = "" ] && ncon=1

target=$3
[ "$target" = "" ] && target=1
#echo "target: $target"
#exit 0

abdir=`dirname $0`
timestamp=`date +%Y%m%d-%H%M%S`
logdir=$HOME/tmp/log_ab
[ -d $logdir ] || mkdir -p $logdir

if [ $target -eq 1 ]; then # wpp_py
	target_name=wpp_py
	ip=192.168.109.56
	port=8080
	urlpath=wlan/distribution
	postfile=$abdir/wpp_req.xml
elif [ $target -eq 2 ]; then # fpp_neu
	target_name=fpp_neu
	ip=192.168.109.58
	#port=18080
	port=8080
	urlpath=FPP_AD/adapter
	postfile=$abdir/fpp_req.xml
elif [ $target -eq 3 ]; then # wpp_vance
	target_name=wpp_vance
	ip=192.168.109.48
	port=8081
	urlpath=wlan/distribution
	postfile=$abdir/wpp_req.xml
elif [ $target -eq 4 ]; then # fpp_moto
	target_name=fpp_moto
	ip=192.168.109.56
	port=18080
	urlpath=fpp/servlet
	postfile=$abdir/fpp_req.xml
elif [ $target -eq 5 ]; then # wpp_local
	target_name=wpp_local
	ip=localhost
	port=8080
	urlpath=wlan/distribution
	postfile=$abdir/wpp_req.xml
elif [ $target -eq 6 ]; then # fpp_neu_pubip
	target_name=fpp_neu_pubip
	ip=218.206.179.209
	port=18080
	urlpath=FPP_AD/adapter
	postfile=$abdir/fpp_req.xml
else
	echo "Unsupported target id: $target"
	exit 99
fi

gplfile=$logdir/${target_name}_n$1c$2_$timestamp.gpl 
csvfile=$logdir/${target_name}_n$1c$2_$timestamp.csv 
url=http://$ip:$port/$urlpath

echo -e "\nTesting: $target_name: $url\n"
ab -n $ntot -c $ncon -p $postfile -g $gplfile -e $csvfile $url
